package org.vsaulyak.springrssagregator.aspect;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;
import org.apache.log4j.Logger;

@Aspect
@Component
public class HttpRequestLogger
{
    @Inject
    private HttpServletRequest request;
    
    private Logger logger;
    
    public HttpRequestLogger()
    {
        logger = Logger.getLogger("org.vsaulyak.springrssagregator");
    }
    
    @Pointcut("execution(* org.vsaulyak.springrssagregator.controller.*.*(..)) "
            + "&& within(@org.springframework.web.bind.annotation.RequestMapping *)")
    public void httpRequest() {}
    
    @Before("httpRequest()")
    public void logHttpRequest()
    {
        logger.info(request.getMethod() + " " + request.getRequestURI());
        //System.out.println(" -- RequestMapping - " + request.getMethod() + " " + request.getRequestURI());
    }
}